﻿
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>统计分析</title>
    <link href="../../DataUser/Style/ccbpm.css" rel="stylesheet" type="text/css" />
    <link href="../Scripts/easyUI/themes/gray/easyui.css" rel="stylesheet" type="text/css" />
    <link href="../Scripts/easyUI/themes/icon.css" rel="stylesheet" type="text/css" />
    <script src="../Scripts/easyUI/jquery-1.8.0.min.js" type="text/javascript"></script>
    <script src="../Scripts/easyUI/jquery.easyui.min.js" type="text/javascript"></script>
    <script src="JS/Calendar/WdatePicker.js" type="text/javascript"></script>
    <link href="JS/Calendar/skin/WdatePicker.css" rel="stylesheet" type="text/css" />
    <script src="../Scripts/EasyUIUtility.js" type="text/javascript"></script>

    <!--引入图表-->
    <script src="FusionCharts/fusioncharts.js" type="text/javascript"></script>
   
    <!--引入公共的JS-->
    <script src="../Scripts/QueryString.js" type="text/javascript"></script>
    <script src="../Scripts/config.js" type="text/javascript"></script>
    <script src="Gener.js" type="text/javascript"></script>
    <style type="text/css">
        input[type=text], input[type=password], select
        {
            border: thin solid #cccccc;
            margin: 2px 1px;
            height: 24px;
            background-color: rgba(255, 255, 255, 0.77);
        }
        td
        {
            border-color:#ccc;
        }
    </style>

    <script type="text/javascript">
        //定义公共个变量.
        var webUser = new WebUser();

        var ensName = GetQueryString("EnsName");
        var OrderBy = this.GetQueryString("OrderBy");
        var OrderWay = this.GetQueryString("OrderWay");
        var NumKey = this.GetQueryString("NumKey");

        //当前用户页面信息.
        var ur = new Entity("BP.Sys.UserRegedit");
        ur.MyPK = webUser.No + ensName + "_Group";

        ur.RetrieveFromDBSources();
        ur.OrderBy = OrderBy;
        ur.OrderWay = OrderWay;
        ur.NumKey = NumKey;
        ur.Save();
        var count = ur.GetPara("RecCount");
        var mapBase;
        var searchAttrs;


        //初始化页面
        $(function () {
            var groupCount = $('input[name="groupContent"]:checked').length;
            if (groupCount > 1)
                $("#CB_IsShowPict").attr("disabled", "disabled");

            if (ur.IsPic == 1)
                document.getElementById("CB_IsShowPict").checked = "checked";

            //初始化按钮
            InitToolbar();
            //显示内容
            DealGroupContent();
            //分析项目
            GroupAnalysis();
            //显示数据
            doPostBack(0);


        });

        //初始化数据.
        function InitToolbar() {

            //创建处理器.
            var handler = new HttpHandler("BP.WF.HttpHandler.WF_Comm");
            handler.AddUrlData();  //增加参数.

            //获得map基本信息.
            mapBase = handler.DoMethodReturnJSON("Group_MapBaseInfo");

            document.title = mapBase.EnDesc;

            if (mapBase.IsView == "false") {
                alert("对不起，您没有查看的权限！");
                return;
            }

            //获得查询信息，包含了查询数据表.
            var data = handler.DoMethodReturnJSON("Group_SearchAttrs");

            //绑定外键枚举查询条件.
            searchAttrs = data["Attrs"];

            //格式为: @WFSta=0@FK_Dept=02
            var json = AtParaToJson(ur.Vals);

            for (var i = searchAttrs.length-1; i >= 0; i--) {

                var attr = searchAttrs[i];
                var str = "";
                str += "<label for='CXDDL_" + attr.Field + "'>" + attr.Name + " : </label><select class='form-control' name='CXDDL_" + attr.Field + "' ID='DDL_" + attr.Field + "'>" + InitDDLOperation(data, attr, "all") + "</select>&nbsp;&nbsp;&nbsp;&nbsp;";
                str = $(str);
                $("#toolBar").prepend(str); //设置基础信息.
            }

            var html = "";
            if (mapBase.IsShowSearchKey == "1")
                html += "<label for='TB_Key'>关键字:</label><input  style='width:100px;' type=text id='TB_Key' name='TB_Key' value='" + ur.SearchKey + "' class='form-control' />&nbsp;&nbsp;&nbsp;&nbsp;";

            if (mapBase.DTSearchWay != "0") {

                html += mapBase.DTSearchLable;

                if (mapBase.DTSearchWay == "1") {
                    html += "<input type=text id='TB_DTFrom' name='TB_DTFrom' value='" + ur.DTFrom + "'  onfocus=\"WdatePicker({dateFmt:'yyyy-MM-dd'})\" style='width:120px;' class='form-control Wdate' />";
                    html += "到<input type=text id='TB_DTTo' name='TB_DTTo' value='" + ur.DTTo + "' onfocus=\"WdatePicker({dateFmt:'yyyy-MM-dd'})\" style='width:120px;' class='form-control Wdate' />&nbsp;&nbsp;&nbsp;&nbsp;";
                } else {
                    html += "<input type=text id='TB_DTFrom' name='TB_DTFrom' value='" + ur.DTFrom + "'  onfocus=\"WdatePicker({dateFmt:'yyyy-MM-dd HH:mm'});\" style='width:135px;' class='form-control Wdate' />";
                    html += "到<input type=text id='TB_DTTo' name='TB_DTTo' value='" + ur.DTTo + "' onfocus=\"WdatePicker({dateFmt:'yyyy-MM-dd HH:mm'});\"  style='width:135px;' class='form-control Wdate' />&nbsp;&nbsp;&nbsp;&nbsp;";
                }
            }

            //绑定外键枚举查询条件.
            var attrs = data["Attrs"];

            //当前用户页面信息.
            var searchUr = new Entity("BP.Sys.UserRegedit");
            searchUr.MyPK = webUser.No + "_" + ensName + "_SearchAttrs";
            searchUr.RetrieveFromDBSources();
            var json = AtParaToJson(searchUr.Vals);

            $("#toolBar").prepend(html); //设置基础信息.

            //为查询外键赋值.
            for (var i = 0; i < attrs.length; i++) {
                var attr = attrs[i];
                var selectVal = json[attr.Field];

                if (selectVal == undefined || selectVal == "")
                    selectVal = "all";

                $("#DDL_" + attr.Field).val(selectVal);
            }

        }
        //初始化下拉列表框的OPERATION
        function InitDDLOperation(frmData, mapAttr, defVal) {

            var operations = "";
            if (defVal == "all")
                operations += "<option value='all' >全部</option>";

            var ens = frmData[mapAttr.Field];
            if (ens == null) {
                ens = [{ 'IntKey': 0, 'Lab': '否' }, { 'IntKey': 1, 'Lab': '是'}];
            }
            for (var i = 0; i < ens.length; i++) {

                var en = ens[i];

                var selected = "";
                if (en.Selected && en.Selected.toString() == "true")
                    selected = "selected=selected";

                if (en.No == undefined)
                    operations += "<option value='" + en.IntKey + "' " + selected + ">" + en.Lab + "</option>";
                else
                    operations += "<option value='" + en.No + "' " + selected + ">" + en.Name + "</option>";
            }
            return operations;
        }

        function DealGroupContent() {
            //创建处理器.
            var handler = new HttpHandler("BP.WF.HttpHandler.WF_Comm");
            handler.AddUrlData();  //增加参数.
            var data = handler.DoMethodReturnJSON("Group_ContentAttrs");
            if (data.indexOf('err@') != -1) {
                alert(data);
                return;
            }
            var groupAttrs = data;
            if (groupAttrs.length == 0) {
                alert("[" + document.title + "]没有外键或枚举，不能做分组查询.");
                return;
            }

            for (var i = 0; i < groupAttrs.length; i++) {
                var html = "";
                var checked = "";
                if (groupAttrs[i].Checked && groupAttrs[i].Checked.toString() == "true") {
                    checked = "checked=checked";
                }
                html += "<tr>";
                html += "<td>";
                html += "<input type='checkbox' id='" + groupAttrs[i].Field + "' name='groupContent' " + checked + " onclick='javascript:doPostBack(1,\"\")' value='" + groupAttrs[i].Field + "'/><label for='" + groupAttrs[i].Field + "'>" + groupAttrs[i].Name + "</label>";
                html += "</td>";
                html += "</tr>";
                $("#CheckBoxList").append(html);
            }

        }
        function GroupAnalysis() {
            //创建处理器.
            var handler = new HttpHandler("BP.WF.HttpHandler.WF_Comm");
            handler.AddUrlData();  //增加参数.
            var data = handler.DoMethodReturnString("Group_Analysis");
            if (data.indexOf('err@') != -1) {
                alert(data);
                return;
            }
            var data = JSON.parse(data);
            var analyAtts = data["Attrs"];


            for (var i = 0; i < analyAtts.length; i++) {
                var html = "";
                var checked = "";
                if (analyAtts[i].Checked && analyAtts[i].Checked.toString() == "true") {
                    checked = "checked=checked";
                }
                html += "<tr>";
                html += "<td>";
                html += "<input type='checkbox' id='" + analyAtts[i].Field + "' name='groupAnaly' " + checked + " onclick='javascript:doPostBack(1,\"\")' value='" + analyAtts[i].Field + "'/><label for='" + analyAtts[i].Field + "'>" + analyAtts[i].Name + "</label>";
                html += "</td>";
                html += "<td style='font-size:12px;text-align:right'>";
                html += "<select class='form-control' name='DDL_" + analyAtts[i].Field + "' ID='DDL_" + analyAtts[i].Field + "' onchange='javascript:doPostBack(1,\"\")'>" + InitDDLOperation(data, analyAtts[i], null) + "</select>&nbsp;&nbsp;&nbsp;&nbsp;";
                html += "</td>";
                html += "</tr>";
                $("#AnalyGroup").append(html);
            }
        }

        function doPostBack() {
            var groupCount = $('input[name="groupContent"]:checked').length;
            if (groupCount != 1) {
                $("#CB_IsShowPict").attr("disabled", "disabled");
                $("#CB_IsShowPict").attr("checked", false);
            }else {
                $("#CB_IsShowPict").attr("disabled", false);
                $("#CB_IsShowPict").attr("checked", true);
            }

            //给注册表信息重新赋值
            ur = new Entity("BP.Sys.UserRegedit");
            ur.MyPK = webUser.No + ensName + "_Group";
            var selectedGroupKey = "";
            $('input[name="groupContent"]:checked').each(function () {
                selectedGroupKey += '@' + $(this).val(); //将选中的值添加到数组chk_value中  
            });
            var stateNumKey = "";
            $('input[name="groupAnaly"]:checked').each(function () {
                var key = $(this).val();
                //获取下拉框的值
                var defVal = $("#DDL_" + key).val();

                stateNumKey += '@' + $(this).val() + '=' + defVal; //将选中的值添加到数组chk_value中  
            });

            ur.Vals = "SelectedGroupKey=" + selectedGroupKey + "@StateNumKey" + stateNumKey + '@';

            if ($("#CB_IsShowPict").is(":checked") == true)
                ur.IsPic = 1;
            else
                ur.IsPic = 0;

            ur.SetPKVal(ur.MyPK);
            ur.FK_Emp = webUser.No;
            ur.CfgKy = ensName;
            ur.Save();

            Group_Search();
        }
        function Group_Search() {
            if (FusionCharts("column_chart") != undefined)
                FusionCharts("column_chart").dispose();
            if (FusionCharts("pie_chart") != undefined)
                FusionCharts("pie_chart").dispose();
            if (FusionCharts("line_chart") != undefined)
                FusionCharts("line_chart").dispose();

            //重新获取注册信息
            ur = new Entity("BP.Sys.UserRegedit");
            ur.MyPK = webUser.No + ensName + "_Group";

            ur.RetrieveFromDBSources();

            //创建处理器.
            var handler = new HttpHandler("BP.WF.HttpHandler.WF_Comm");
            handler.AddUrlData();  //增加参数.
            handler.AddFormData();
            var groupList = "";
            $('input[name="groupContent"]').each(function () {
                groupList += '@' + $(this).val(); //将选中的值添加到数组chk_value中  
            });
            handler.AddPara("GroupList", groupList);

            var data = handler.DoMethodReturnString("Group_Search");
            if (data.indexOf('err@') != -1) {
                alert(data);
                return;
            }

            if (data.indexOf('info@') != -1) {
                data = data.replace("info@", "");
                $("#Content").html("").append(data);
                return;
            }
            var data = JSON.parse(data);
            var groupSearch = data["GroupSearch"];
            var AttrsOfNum = data["AttrsOfNum"];
            var AttrsOfGroup = data["AttrsOfGroup"];
            var ActiveAttr = data["ActiveAttr"];
            var noShowSum = data["NoShowSum"].NoShowSum;
            if (noShowSum == null)
                noShowSum = "";

            //生成表格
            if (ur.IsPic == 0) {
                GenerTable("Content", groupSearch, AttrsOfNum, AttrsOfGroup, ur, ActiveAttr, noShowSum);
                //生成图表
            } else {
                GenerChart(groupSearch, AttrsOfGroup, AttrsOfNum, ur, ActiveAttr, noShowSum);
            }

        }

        function GenerTable(divId, groupSearch, AttrsOfNum, AttrsOfGroup, ur, ActiveAttr, noShowSum) {
            var html = "<table id='mainTable'  class='Table' cellspacing='0' cellpadding='0' border='0' style='border-style:none;width:100%' > ";
            //生成表头

            /**含有合计的时候**/
            if (ur.Vals.indexOf("=AMOUNT") != -1) {
                html += "<tr>";
                html += "<td rowspan=2 class='GroupTitle' style='background-color:#eee'>ID</td>";

                for (var i = 0; i < AttrsOfGroup.length; i++) {
                    html += "<td rowspan=2 class='GroupTitle' style='background-color:#eee'>" + AttrsOfGroup[i].Name + "</td>";
                }

                // 增加数据列
                for (var i = 0; i < AttrsOfNum.length; i++) {
                    if (ur.Vals.indexOf.indexOf(AttrsOfNum[i].KeyOfEn + "=AMOUNT") != -1)
                    /*  如果本数据列 包含累计 */
                        html += "<td  colspan=2 class='GroupTitle' style='background-color:#eee' >" + AttrsOfNum[i].Name + "</td>";
                    else
                        html += "<td  rowspan=2 class='GroupTitle' style='background-color:#eee'>" + AttrsOfNum[i].Name + "</td>";
                }
                html += "</tr>";
                html += "<tr>";
                for (var i = 0; i < AttrsOfNum.length; i++) {
                    if (ur.Vals.indexOf(AttrsOfNum[i].KeyOfEn + "=AMOUNT") == -1)
                        continue;

                    html += "<td class='GroupTitle'>本月</td>"; //本月 this.ToE("OrderCondErr")
                    html += "<td class='GroupTitle'>累计</td>"; //累计
                }

                html += "</tr>";

            } else {
                html += "<tr>";
                html += "<td class='GroupTitle' style='text-align:center;background-color:#eee' >序</td>";
                html += "</td>";
                // 分组条件
                for (var i = 0; i < AttrsOfGroup.length; i++) {

                    if (OrderBy == AttrsOfGroup[i].KeyOfEn) {
                        switch (OrderWay) {
                            case "Down":
                                html += "<td class='GroupTitle' style='background-color:#eee'><a href='Group.htm?EnsName=" + GetQueryString("EnsName") + "&OrderBy=" + AttrsOfGroup[i].KeyOfEn + "&OrderWay=Up' >" + AttrsOfGroup[i].Name + "<img src='../Img/ArrDown.gif' border=0/></a></td>";
                                break;
                            case "Up":
                            default:
                                html += "<td class='GroupTitle' style='background-color:#eee'><a href='Group.htm?EnsName=" + GetQueryString("EnsName") + "&OrderBy=" + AttrsOfGroup[i].KeyOfEn + "&OrderWay=Down' >" + AttrsOfGroup[i].Name + "<img src='../Img/ArrUp.gif' border=0/></a></td>";
                                break;
                        }
                    }
                    else {
                        html += "<td class='GroupTitle' style='background-color:#eee'><a href='Group.htm?EnsName=" + GetQueryString("EnsName") + "&OrderBy=" + AttrsOfGroup[i].KeyOfEn + "&OrderWay=Down' >" + AttrsOfGroup[i].Name + "</a></td>";
                    }
                }

                // 分组数据
                for (var i = 0; i < AttrsOfNum.length; i++) {
                    var lab = "";
                    if (ur.Vals.indexOf(AttrsOfNum[i].KeyOfEn + "=SUM") != -1) {
                        lab = "(合计)" + AttrsOfNum[i].Name;
                    }
                    else {
                        lab = "(平均)" + AttrsOfNum[i].Name;
                    }

                    if (OrderBy == AttrsOfNum[i].KeyOfEn) {
                        switch (OrderWay) {
                            case "Down":
                                if (NumKey == AttrsOfNum[i].KeyOfEn)
                                    html += "<td class='GroupTitle' style='background-color:#eee'>" + lab + "<a href='Group.htm?EnsName=" + ensName + "&NumKey=" + AttrsOfNum[i].KeyOfEn + "&OrderBy=" + AttrsOfNum[i].KeyOfEn + "&OrderWay=Up'><img src='../Img/ArrDown.gif' border=0/></a></td>";
                                else
                                    html += "<td class='GroupTitle' style='background-color:#eee'><a href=\"Group.htm?EnsName=" + ensName + "&NumKey=" + AttrsOfNum[i].KeyOfEn + "\" >" + lab + "</a><a href='Group.htm?EnsName=" + ensName + "&NumKey=" + AttrsOfNum[i].KeyOfEn + "&OrderBy=" + AttrsOfNum[i].KeyOfEn + "&OrderWay=Up'><img src='../Img/ArrDown.gif' border=0/></a></td>";
                                break;
                            case "Up":
                            default:
                                if (NumKey == AttrsOfNum[i].KeyOfEn)
                                    html += "<td class='GroupTitle' style='background-color:#eee'>" + lab + "<a href='Group.htm?EnsName=" + ensName + "&OrderBy=" + AttrsOfNum[i].KeyOfEn + "&NumKey=" + AttrsOfNum[i].KeyOfEn + "&OrderWay=Down'><img src='../Img/ArrUp.gif' border=0/></a></td>";
                                else
                                    html += "<td class='GroupTitle' nowrap><a href=\"Group.htm?EnsName=" + ensName + "&NumKey=" + AttrsOfNum[i].KeyOfEn + "\" >" + lab + "</a><a href='Group.htm?EnsName=" + ensName + "&OrderBy=" + AttrsOfNum[i].KeyOfEn + "&NumKey=" + AttrsOfNum[i].KeyOfEn + "&OrderWay=Down'><img src='../Img/ArrUp.gif' border=0/></a></td>";
                                break;
                        }
                    }
                    else {
                        if (NumKey == AttrsOfNum[i].KeyOfEn)
                            html += "<td class='GroupTitle' style='background-color:#eee'>" + lab + "<a href='Group.htm?EnsName=" + ensName + "&NumKey=" + AttrsOfNum[i].KeyOfEn + "&OrderBy=" + AttrsOfNum[i].KeyOfEn + "' ><img src='../Img/ArrDownUp.gif' border=0/></a></td>";
                        else
                            html += "<td class='GroupTitle' style='background-color:#eee'><a href=\"Group.htm?EnsName=" + ensName + "&NumKey=" + AttrsOfNum[i].KeyOfEn + "\" >" + lab + "</a><a href='Group.htm?EnsName=" + ensName + "&NumKey=" + AttrsOfNum[i].KeyOfEn + "&OrderBy=" + AttrsOfNum[i].KeyOfEn + "' ><img src='../Img/ArrDownUp.gif' border=0/></a></td>";

                    }
                }
                html += "<td class='GroupTitle' style='background-color:#eee'></td>";
            }

            html += "</tr>"

            //生成详情的url searchAttrs
            var baseUrl = "ContrastDtl.htm?EnsName=" + ensName + "&TitleName=" + mapBase.EnDesc;
            var keys = "";

            // 分组的信息中是否包含部门？
            var IsHaveFK_Dept = false;
            if (ur.Vals.indexOf("FK_Dept") != -1)
                IsHaveFK_Dept = true;

            for (var i = 0; i < searchAttrs.length; i++) {
                var attr = searchAttrs[i];

                if (attr.MyFieldType == 6)
                    continue;

                if (IsHaveFK_Dept && attr.Field == "FK_Dept")
                    continue;

                var val = $("#DDL_" + attr.Field).val();

                if (val == "all")
                    continue;
                if (keys.indexOf(attr.Field) == -1)
                    keys += "&" + attr.Field + "=" + val;
            }

            baseUrl = baseUrl + keys;


            //生成数据行
            for (var i = 0; i < groupSearch.length; i++) {
                var url = "";
                var dr = groupSearch[i];
                $.each(AttrsOfGroup, function (k, o) {
                    if (url.indexOf(o.KeyOfEn) == -1)
                        url += "&" + o.KeyOfEn + "=" + dr[o.KeyOfEn];
                });


                if ((i + 1) % 2 == 0)
                    html += "<tr bgcolor='AliceBlue' >";
                else
                    html += "<tr bgcolor='white' >";
                html += "<td class='Idx' nowrap>" + dr.IDX + "</td>";
                for (var j = 0; j < AttrsOfGroup.length; j++) {
                    html += "<td  nowrap >" + dr[AttrsOfGroup[j].KeyOfEn + "T"] + "</td>";
                }
                for (var j = 0; j < AttrsOfNum.length; j++) {
                    var obj = dr[AttrsOfNum[j].KeyOfEn];
                    if (obj == null || obj == undefined) obj = "-";
                    if (AttrsOfNum[j].MyDataType == 8) {
                        if (ur.Vals.indexOf(AttrsOfNum[j].KeyOfEn + "=AMOUNT") != -1) {
                            //需要转换为金额类型，小数位数不到两位的补全,功能待定
                            html += "<td class='TDNum' nowrap >" + obj + "</td>";
                            html += "<td class='TDNum' nowrap >" + dr[AttrsOfNum[j].KeyOfEn + "Amount"] + "</td>";
                        } else {
                            html += "<td class='TDNum' nowrap >" + obj + "</td>";
                        }
                    } else {
                        if (ur.Vals.indexOf(AttrsOfNum[j].KeyOfEn + "=AMOUNT") != -1) {
                            html += "<td class='TDNum' nowrap >" + obj + "</td>";
                            html += "<td class='TDNum' nowrap >" + dr[AttrsOfNum[j].KeyOfEn + "Amount"] + "</td>";
                        } else {
                            html += "<td class='TDNum' nowrap >" + obj + "</td>";
                        }
                    }
                }
                url = baseUrl + url;
                html += "<td nowrap ><a href=\"javascript:WinOpen('" + url + "', 'wincommgroup',900,900);\"  class='easyui-linkbutton'>详细</a></td>";
                html += "</tr>";
            }

            //汇总信息
            html += "<tr class='TRSum'>";
            html += "<td nowrap>汇总</td>";
            for (var j = 0; j < AttrsOfGroup.length; j++) {
                html += "<td  nowrap ></td>";
            }
            var AttrsOfNum1 = AttrsOfNum;
            var d = 0;
            for (var i = 0; i < AttrsOfNum.length; i++) {
                if (noShowSum.indexOf("@" + AttrsOfNum[i].KeyOfEn + "@") != -1) {
                    var isHave = false;
                    for (var j = 0; j < ActiveAttr.length; j++) {
                        if (ActiveAttr[j].AttrKey != AttrsOfNum[i].KeyOfEn)
                            continue;

                        isHave = true;

                        var exp = ActiveAttr[j].ExpApp;
                        if (exp == null || exp == "") {
                            html += "<td></td>";
                            break;
                        }

                        for (var k = 0; k < AttrsOfNum1.length; k++) {
                            if (exp.indexOf("@" + AttrsOfNum1[k].KeyOfEn + "@") != -1) {
                                d = 0;
                                $.each(groupSearch, function (i, o) {
                                    d += parseFloat(o[AttrsOfNum1[k].KeyOfEn]);
                                });

                                exp = exp.replace("@" + AttrsOfNum1[k].KeyOfEn + "@", d);
                            }
                        }

                        var handler = new HttpHandler("BP.WF.HttpHandler.WF_Comm");
                        handler.AddPara("Exp", exp);
                        var data = handler.DoMethodReturnString("ParseExpToDecimal");
                        //待定
                        html += "<td class='TDNum' nowrap >" + data.toFixed(4) + "</td>";
                    }

                    if (isHave == false)
                        html += "<td></td>";

                    continue;
                }

                switch (AttrsOfNum[i].MyDataType) {
                    case 8:
                        if (ur.Vals.indexOf(AttrsOfNum[i].KeyOfEn + "=AMOUNT") != -1) {
                            d = 0;
                            $.each(groupSearch, function (k, o) {
                                if (o[AttrsOfNum[i].KeyOfEn] != null && o[AttrsOfNum[i].KeyOfEn] != undefined)
                                d += parseFloat(o[AttrsOfNum[i].KeyOfEn]);
                            });
                            html += "<td class='TDNum' nowrap >" + d.toFixed(4) + "</td>";

                            d = 0;
                            $.each(groupSearch, function (k, o) {
                                if (o[AttrsOfNum[i].KeyOfEn + "Amount"] != null && o[AttrsOfNum[i].KeyOfEn + "Amount"] != undefined)
                                d += parseFloat(o[AttrsOfNum[i].KeyOfEn + "Amount"]);
                            });
                            html += "<td class='TDNum' nowrap >" + d.toFixed(4) + "</td>";
                        }
                        else {
                            d = 0;
                            $.each(groupSearch, function (k, o) {
                                if (o[AttrsOfNum[i].KeyOfEn + "Amount"] != null && o[AttrsOfNum[i].KeyOfEn + "Amount"] != undefined)
                                d += parseFloat(o[AttrsOfNum[i].KeyOfEn + "Amount"]);
                            });

                            if (ur.Vals.indexOf(AttrsOfNum[i].KeyOfEn + "=AVG") < 1)
                                html += "<td class='TDNum' nowrap >" + d.toFixed(4) + "</td>";
                            else {
                                if (groupSearch.length == 0)
                                    html += "<td class='TDNum' nowrap ></td>";
                                else
                                    html += "<td class='TDNum' nowrap >" + (d / groupSearch.length).toFixed(4) + "</td>";
                            }
                        }
                        break;
                    default:
                        if (ur.Vals.indexOf(AttrsOfNum[i].KeyOfEn + "=AMOUNT") != -1) {
                            d = 0;
                            $.each(groupSearch, function (k, o) {
                                if (o[AttrsOfNum[i].KeyOfEn] != null && o[AttrsOfNum[i].KeyOfEn] != undefined)
                                    d += parseFloat(o[AttrsOfNum[i].KeyOfEn]);
                            });

                            html += "<td class='TDNum' nowrap >" + d + "</td>";

                            d = 0;
                            $.each(groupSearch, function (k, o) {
                                if (o[AttrsOfNum[i].KeyOfEn + "Amount"] != null && o[AttrsOfNum[i].KeyOfEn + "Amount"] != undefined)
                                d += parseFloat(o[AttrsOfNum[i].KeyOfEn + "Amount"]);
                            });
                            html += "<td class='TDNum' nowrap >" + d + "</td>";

                        } else {
                            d = 0;
                            $.each(groupSearch, function (k, o) {
                                if(o[AttrsOfNum[i].KeyOfEn]!=null && o[AttrsOfNum[i].KeyOfEn]!=undefined)
                                    d += parseFloat(o[AttrsOfNum[i].KeyOfEn]);
                            });

                            if (ur.Vals.indexOf(AttrsOfNum[i].KeyOfEn + "=AVG") == -1)
                                html += "<td class='TDNum' nowrap >" + d + "</td>";
                            else {
                                if (groupSearch.length == 0)
                                    html += "<td class='TDNum' nowrap ></td>";
                                else
                                    html += "<td class='TDNum' nowrap >" + (d / groupSearch.length).toFixed(4) + "</td>";
                            }
                        }
                        break;

                }
            }
            html += "<td class='TDNum' nowrap ></td>";
            html += "</tr>";
            html += "</table>";
            $("#" + divId).html("").append(html);
        }



        function GenerChart(groupSearch, AttrsOfGroup, AttrsOfNum, ur, ActiveAttr, noShowSum) {
            var html = "";
            //增加分组
            html += "<div class='easyui-tabs' data-options=\"fit:true\">";
            html += "<div id='table_div' title='分组数据' data-options=\"iconCls:'icon-table'\" style='padding:5px'></div>";
            //增加柱状图像
            html += "<div id='column_chart_div'  title='柱状图' data-options=\"iconCls:'icon-columnchart'\" style='padding:5px;text-align:center'></div>";
            //增加饼图
            html += "<div id='pie_chart_div' title='饼状图' data-options=\"iconCls:'icon-piechart'\" style='padding:5px;text-align:center'></div>";
            //增加折线图
            html += "<div  id='line_chart_div' title='折线图' data-options=\"iconCls:'icon-linechart'\" style='padding:5px;text-align:center'></div>";
            html += "</div>";
            var width = $("#TB_W").val();
            if (width == "" || width == 0)
                width = 300;
            var height = $("#TB_H").val();
            if (height == "" || height == 0)
                height = 300;

            $("#Content").html("").append(html);
            $.parser.parse("#Content");

            //获取url项目的名称
            var projectName = "";
            if (plant != "CCFlow") {
                var pathName = window.location.pathname.substring(1); //jflow-web/WF/Comm/Group.htm
                projectName = pathName.substring(0, pathName.substr(1).indexOf('/') + 1);
            }
            GenerTable("table_div", groupSearch, AttrsOfNum, AttrsOfGroup, ur, ActiveAttr, noShowSum);
            GenerateColumnChart(groupSearch, AttrsOfGroup[0].KeyOfEn, AttrsOfNum, width, height, projectName);
            GeneratePieChart(groupSearch, AttrsOfGroup[0].KeyOfEn, AttrsOfNum, width, height, projectName);
            GenerateLineChart(groupSearch, AttrsOfGroup[0].KeyOfEn, AttrsOfNum, width, height, projectName);
        }

        //柱状图像
        function GenerateColumnChart(groupSearch, KeyOfEn, AttrsOfNum, w, h, projectName) {
            var categories = "[{\"category\": [";
            for (var i = 0; i < groupSearch.length; i++) {
                categories += "{ \"label\":\"" + groupSearch[i][KeyOfEn + "T"] + "\"},";
            }
            categories = categories.substr(0, categories.length - 1);
            categories += "]}]";
            categories = JSON.parse(categories);
            var dataSet = "[";
            for (var i = 0; i < AttrsOfNum.length; i++) {
                if (AttrsOfNum[i].Name == null || AttrsOfNum[i].Name == "")
                    continue;
                dataSet += "{\"seriesname\":\"" + AttrsOfNum[i].Name + "\",\"data\":[";
                for (var j = 0; j < groupSearch.length; j++) {
                    dataSet += "{\"value\":\"" + +groupSearch[j][AttrsOfNum[i].KeyOfEn] + "\"},";
                }
                dataSet = dataSet.substr(0, dataSet.length - 1);
                dataSet += "]},";
            }
            dataSet = dataSet.substr(0, dataSet.length - 1);
            dataSet += "]";
            dataSet = JSON.parse(dataSet);
            var dataSource = {
                "chart": {
                    "exportEnabled": '0',
                    "exportAtClient": '1',
                    "exportHandler": 'fcExporter1',
                    "exportFormats": 'PNG=生成PNG图片|JPG=生成JPG图片|PDF=生成PDF文件',
                    "decimalPrecision": '4',
                    "hoverCapBgColor": 'ffffff', "bgColor": 'B8D288,FFFFFF', "outCnvBaseFontSize": '12', "anchorBgColor": '008ED6', "caption": document.title,
                    "AlternateHGridColor": 'ff5904', "divLineColor": 'ff5904', "divLineAlpha": '20', "alternateHGridAlpha": '5',
                    "showNames": '1', "showValues": '1', "showAlternateHGridColor": '1',
                    "decimalPrecision": '0', "formatNumberScale": '0'
                },
                "categories": categories,
                "dataset": dataSet
            };
            
             FusionCharts.ready(function(){
                var myChart = new FusionCharts({
                    type: "mscolumn2d",
                    id: "column_chart",
                   renderAt: "chart-container",
                   width: w,
                   height: h,
                   dataFormat: "json",
                   dataSource:dataSource
                }).render("column_chart_div");
            });
           

        }
        //饼图
        function GeneratePieChart(groupSearch, KeyOfEn, AttrsOfNum, w, h, projectName) {
            var firstKey = AttrsOfNum[0];
         
            var categories = "[{\"category\": [";
            for (var i = 0; i < groupSearch.length; i++) {
                categories += "{ \"label\":\"" + groupSearch[i][KeyOfEn + "T"] + "\"},";
            }
            categories = categories.substr(0, categories.length - 1);
            categories += "]}]";
            categories = JSON.parse(categories);
            var dataSet = "[{\"data\":[";
            for (var j = 0; j < groupSearch.length; j++) {
                dataSet += "{\"label\":\"" + groupSearch[j][KeyOfEn + "T"] + "\",\"value\":\"" + +groupSearch[j][firstKey.KeyOfEn] + "\" },";
            }
            
            dataSet = dataSet.substr(0, dataSet.length - 1);
            dataSet += "]}]";
            dataSet = JSON.parse(dataSet);
            var dataSource = {
                "chart": {
                    //"exportEnabled": '0',
                    //"exportAtClient": '1',
                    //"exportHandler": 'fcExporter1',
                   // "exportFormats": 'PNG=生成PNG图片|JPG=生成JPG图片|PDF=生成PDF文件',
                    "caption": document.title + "-" + firstKey.Name,
                    "showValues":"1",
                    "numberSuffix": "%",
                    "theme": "hulk-light",
                    "enableMultiSlicing":"1",
                    "outCnvBaseFontColor":'FFFFFF',
                     "hoverCapBgColor": '2E4A89',
                     //"basefontcolor": 'ccdee',
                     "basefontsize": '14',
                    "bgColor": '2E4A89, 90B1DE', "palette": '2', "animation": '1' ,
                    "formatNumberScale":'0', "pieSliceDepth":'30', "startingAngle":'125'
                },
                "dataset": dataSet
            };

            FusionCharts.ready(function () {
                var myChart = new FusionCharts({
                    type: "Pie3d",
                    id: "pie_chart",
                    renderAt: "chart-container",
                    width: w,
                    height: h,
                    dataFormat: "json",
                    dataSource: dataSource
                }).render("pie_chart_div");
            });
        }
        //折线图
        function GenerateLineChart(groupSearch, KeyOfEn, AttrsOfNum, w, h, projectName) {
            

            var categories = "[{\"category\": [";
            for (var i = 0; i < groupSearch.length; i++) {
                categories += "{ \"label\":\"" + groupSearch[i][KeyOfEn + "T"] + "\"},";
            }
            categories = categories.substr(0, categories.length - 1);
            categories += "]}]";
            categories = JSON.parse(categories);
            var dataSet = "[";
            for (var i = 0; i < AttrsOfNum.length; i++) {
                if (AttrsOfNum[i].Name == null || AttrsOfNum[i].Name == "")
                    continue;
                dataSet += "{\"seriesname\":\"" + AttrsOfNum[i].Name + "\",\"data\":[";
                for (var j = 0; j < groupSearch.length; j++) {
                    dataSet += "{\"value\":\"" + +groupSearch[j][AttrsOfNum[i].KeyOfEn] + "\"},";
                }
                dataSet = dataSet.substr(0, dataSet.length - 1);
                dataSet += "]},";
            }
            dataSet = dataSet.substr(0, dataSet.length - 1);
            dataSet += "]";
            dataSet = JSON.parse(dataSet);
            var dataSource = {
                "chart": {
                    "exportEnabled": '0',
                    "exportAtClient": '1',
                    "exportHandler": 'fcExporter1',
                    "exportFormats": 'PNG=生成PNG图片|JPG=生成JPG图片|PDF=生成PDF文件',
                    "decimalPrecision": '4',
                    "hoverCapBgColor": 'ffffff', "bgColor": 'B8D288,FFFFFF', "outCnvBaseFontSize": '12', "anchorBgColor": '008ED6', "caption": document.title,
                    "AlternateHGridColor": 'ff5904', "divLineColor": 'ff5904', "divLineAlpha": '20', "alternateHGridAlpha": '5',
                    "showNames": '1', "showValues": '1', "showAlternateHGridColor": '1',
                    "decimalPrecision": '0', "formatNumberScale": '0'
                },
                "categories": categories,
                "dataset": dataSet
            };

            FusionCharts.ready(function () {
                var myChart = new FusionCharts({
                    type: "MSLine",
                    id: "line_chart",
                    renderAt: "chart-container",
                    width: w,
                    height: h,
                    dataFormat: "json",
                    dataSource: dataSource
                }).render("line_chart_div");
            });
        }

        function Search() {
            //保存查询条件.
            var ensName = GetQueryString("EnsName");
            var ur = new Entity("BP.Sys.UserRegedit");
            ur.MyPK = webUser.No + "_" + ensName + "_SearchAttrs";
            ur.FK_Emp = webUser.No;

            if ($("#TB_Key") != null && $("#TB_Key").val() != "")
                ur.SearchKey = $("#TB_Key").val();
            else
                ur.SearchKey = "";

            //设置查询时间.
            if ($("#TB_DTFrom").length == 1)
                ur.DTFrom = $("#TB_DTFrom").val();

            if ($("#TB_DTTo").length == 1)
                ur.DTTo = $("#TB_DTTo").val();

            //获得外键的查询条件,存储里面去.
            var str = "";
            $("select[name^='CXDDL_']").each(function () {
                var id = $(this).attr("id");
                id = id.replace("DDL_", "");
                str += "@" + id + "=" + $(this).val();
            });

            ur.FK_Emp = webUser.No;
            ur.CfgKey = "SearchAttrs";
            ur.Vals = str;
            ur.FK_MapData = ensName;
            ur.SetPara("RecCount", count);
            ur.Save();
            //查询
            Group_Search();

        }

        function Exp() {
            var handler = new HttpHandler("BP.WF.HttpHandler.WF_Comm");
            handler.AddPara("EnsName", GetQueryString("EnsName"));
            //查询集合
            var data = handler.DoMethodReturnString("Group_Exp");
            var url = "";
            if (data.indexOf('err@') == 0) {
                alert(data);
            }
            if (plant != 'CCFlow') {
                var currentPath = window.document.location.href;
                var path = currentPath.substring(0, currentPath.indexOf('/WF') + 1);
                data = path + data;
            }
            window.open(data);
            return;

        }

        function WinOpen(url, winName) {
            var newWindow = window.open(url, winName, 'height=800,width=1030,top=' + (window.screen.availHeight - 800) / 2 + ',left=' + (window.screen.availWidth - 1030) / 2 + ',scrollbars=yes,resizable=yes,toolbar=false,location=false,center=yes,center: yes;');
            newWindow.focus();
            return;
        }

    </script>
</head>
<body class="easyui-layout">
   <form  id="cc">
        <div id="mainDiv" data-options="region:'center',title:'学生',noheader:true" style="padding: 5px">
            <div class="easyui-layout"  data-options="fit:true">
                <div id="toolBar" data-options="region:'north',noheader:true,split:false" style="padding: 2px;height: 34px; line-height: 30px">
                     <a href="#" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-search'" onclick="Search()">查询</a>
                      <a href="#"  class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-excel'" onclick="Exp()">导出全部</a>
                </div>
                <div data-options="region:'west',title:'分组条件',split:true" style="padding: 5px; width: 260px;">
                    <div class="easyui-panel" title="显示内容" style="padding: 5px; margin-bottom: 5px">
                        <table id="CheckBoxList" style="border-style:None;width:100%;"></table>
                    </div>
                    <div class="easyui-panel" title="分析项目" style="padding: 5px; margin-bottom: 5px">
                        <table id="AnalyGroup"  cellspacing='0' cellpadding='0' border='0' style='border-style:none;width:100%' ></table>
                    </div>
                    <div class="easyui-panel" title="图表" style="padding: 5px; margin-bottom: 5px">
                        <table cellpadding="0" cellspacing="0" border="0" style="border-style: none; width: 100%">
                            <tr>
                                <td>
                                    高度：<input name="TB_H" type="text" value="460" id="TB_H"  class="aspNetDisabled" style="width: 60px; height: auto;
                                        text-align: right" />
                                </td>
                                <td style="text-align: right">
                                    宽度：<input name="TB_W" type="text" value="800" id="TB_W"  class="aspNetDisabled" style="width: 60px; height: auto;
                                        text-align: right" />
                                </td>
                            </tr>
                            <tr>
                                <td colspan="2">
                                    <span class="aspNetDisabled" title="注意：仅当“显示内容”选择1项时，图表功能才可用！" style="float: left">
                                        <input id="CB_IsShowPict" type="checkbox" name="CB_IsShowPict"  onclick="javascript:doPostBack()" />
                                        <label for="CB_IsShowPict">显示图表</label>
                                    </span>
                                    <span style="float: right">
                                        <a id="lbtnApply" class="aspNetDisabled easyui-linkbutton" data-options="iconCls:&#39;icon-ok&#39;,plain:true">应用</a></span>
                                </td>
                            </tr>
                        </table>
                    </div>
                </div>
                <div id="Content" data-options="region:'center'" style="padding: 5px;"></div>
           </div>
        </div>
    </form>
</body>
</html>
